  <div class="entry">
    <div class="top">
      <div class="progress">
        <%= display_progress(goal) %>
      </div>
      <%= link_to(h(goal.name), goals_url(:id => goal.id)) %>
    </div>
    <div class="main goal_body">
      <div class="summary">
        <div class="header">
          Summary
        </div>
        <div class="text">
          <%= h(goal.summary) %>
        </div>
        <br class="clear"/>
      </div>
      <div class="progress-text">
        <div class="header">
          <%= goal.completed? ? "Results" : "Progress" %> 
        </div>
        <div class="text">
          <div class="emphasis">
            <%= (goal.progress.success.to_f / goal.progress.total * 100).ceil %>% successful <%= goal.completed? ? "(completed)" : "to date" %> 
          </div>
          <%= "#{goal.progress.success} of #{pluralize(goal.progress.total, "checkpoint")} succeeded.<br/>" if goal.progress.success > 0 %>
          <%= "#{goal.progress.failure} of #{pluralize(goal.progress.total, "checkpoint")} failed.<br/>" if goal.progress.failure > 0 %>
          <%= "#{goal.progress.pending} of #{pluralize(goal.progress.total, "checkpoint")} pending.<br/>" if goal.progress.pending > 0 %>
        </div>
        <br class="clear"/>
      </div>
      
      <div class="togglable toggle_off">
        <div class="details_toggle">  
          <%= link_to_function(
                "Details",
                "Application.toggle(this)",
                {},
                { :class => "dark" }
                ) %>
        </div>
        <div class="details">
          <% if !goal.description.blank? %>
            <b>Description:</b>
            <br/>
            <%= goal.description.untaint %>
            <br/><br/>
          <% end %>
          
          <% if goal.interval && goal.interval_unit %>
            <b>Checkpoint Recurrence:</b>
            <br/>
            Recurs every <%= pluralize(goal.interval, goal.interval_unit) %> 
              from <%= goal.begin_at.strftime("%Y.%m.%d") %> to <%= goal.end_at.strftime("%Y.%m.%d") %>.
            <br/><br/>
          <% end %>
          
          <b><%= goal.completed? ? "Results" : "Progress" %> Analysis:</b>
          <br/>
          <div class="progress_percentage">
            <% success   = (goal.progress.success / goal.progress.total).ceil %>
            <% failure   = (goal.progress.failure / goal.progress.total).ceil %>
            <% pending   = 100 - success - failure %>
            <%= "Pending: #{pending}%" if pending > 0 %>
            <%= "Failure: #{failure}%" if failure > 0 %>
            <%= "Success: #{success}%" if success > 0 %>
          </div>
          <table class="checkpoints" cellspacing="3" cellpadding="0">
            <% goal.goal_checkpoints.each do |checkpoint| %>
              <%= display_checkpoint checkpoint %>
            <% end %>
          </table>
        </div>
      </div>
      <br class="clear"/>
    </div>
    <div class="bottom">
      <div class="timestamp float right">
        Created on <%= goal.created_at.to_s(:long) %>
      </div>
      <div class="comments-toggle">
        <%= link_to_function(
              pluralize(goal.comments.size, "Comment"), 
              "$(this).up('div.entry').down('div.comments').toggle(); return false;" )%>
      </div>
      <br class="clear"/>
    </div>
    <div class="comments" style="<%= "display: none;" unless @permalinked %>">
      <%= render :partial => "comments/list", :locals => { :target => goal } %>
    </div>
  </div>
